38834-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-02-28 10:42:04 +00:00

5808 lines
110 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const DataProviders = db.data_providers;
const ApiCredentials = db.api_credentials;
const MarketIndicators = db.market_indicators;
const IndicatorObservations = db.indicator_observations;
const RegimeModels = db.regime_models;
const RegimeRules = db.regime_rules;
const RegimeDetections = db.regime_detections;
const AssetUniverse = db.asset_universe;
const Portfolios = db.portfolios;
const PortfolioPositions = db.portfolio_positions;
const AllocationPolicies = db.allocation_policies;
const RegimeAllocations = db.regime_allocations;
const RebalancingRecommendations = db.rebalancing_recommendations;
const FetchJobs = db.fetch_jobs;
const JobRuns = db.job_runs;
const DataProvidersData = [
{
"name": "Marie Curie",
"provider_type": "market_data_api",
"base_url": "Marie Curie",
"is_enabled": false,
"notes": "Grace Hopper",
},
{
"name": "Ada Lovelace",
"provider_type": "internal",
"base_url": "Marie Curie",
"is_enabled": true,
"notes": "Grace Hopper",
},
{
"name": "Marie Curie",
"provider_type": "demo",
"base_url": "Ada Lovelace",
"is_enabled": false,
"notes": "Marie Curie",
},
{
"name": "Grace Hopper",
"provider_type": "demo",
"base_url": "Marie Curie",
"is_enabled": false,
"notes": "Marie Curie",
},
];
const ApiCredentialsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"label": "Marie Curie",
"key_name": "Marie Curie",
"secret_value": "Marie Curie",
"is_active": true,
"rotated_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"label": "Grace Hopper",
"key_name": "Alan Turing",
"secret_value": "Grace Hopper",
"is_active": true,
"rotated_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"label": "Ada Lovelace",
"key_name": "Grace Hopper",
"secret_value": "Ada Lovelace",
"is_active": true,
"rotated_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"label": "Marie Curie",
"key_name": "Grace Hopper",
"secret_value": "Grace Hopper",
"is_active": true,
"rotated_at": new Date(Date.now()),
},
];
const MarketIndicatorsData = [
{
"name": "Marie Curie",
"indicator_type": "commodity_momentum",
"description": "Grace Hopper",
"symbol": "Grace Hopper",
"symbol_type": "continuous_future",
"source_field": "Alan Turing",
// type code here for "relation_one" field
"frequency": "weekly",
"units": "Marie Curie",
"lookback_days": 1,
"normalization_min": 1.45,
"normalization_max": 5.0,
"is_enabled": false,
},
{
"name": "Grace Hopper",
"indicator_type": "custom",
"description": "Grace Hopper",
"symbol": "Ada Lovelace",
"symbol_type": "continuous_future",
"source_field": "Ada Lovelace",
// type code here for "relation_one" field
"frequency": "intraday",
"units": "Alan Turing",
"lookback_days": 5,
"normalization_min": 6.99,
"normalization_max": 9.77,
"is_enabled": false,
},
{
"name": "Alan Turing",
"indicator_type": "custom",
"description": "Grace Hopper",
"symbol": "Marie Curie",
"symbol_type": "fred_series",
"source_field": "Ada Lovelace",
// type code here for "relation_one" field
"frequency": "daily",
"units": "Ada Lovelace",
"lookback_days": 8,
"normalization_min": 2.07,
"normalization_max": 3.08,
"is_enabled": false,
},
{
"name": "Alan Turing",
"indicator_type": "equity_volatility",
"description": "Alan Turing",
"symbol": "Marie Curie",
"symbol_type": "fred_series",
"source_field": "Marie Curie",
// type code here for "relation_one" field
"frequency": "intraday",
"units": "Grace Hopper",
"lookback_days": 5,
"normalization_min": 7.62,
"normalization_max": 3.42,
"is_enabled": false,
},
];
const IndicatorObservationsData = [
{
// type code here for "relation_one" field
"observed_at": new Date(Date.now()),
"raw_value": 4.49,
"normalized_value": 2.02,
"change_1d": 3.8,
"change_5d": 3.81,
"z_score": 0.19,
"quality_flag": "stale",
"source_reference": "Marie Curie",
"notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
"observed_at": new Date(Date.now()),
"raw_value": 3.08,
"normalized_value": 6.52,
"change_1d": 4.43,
"change_5d": 4.64,
"z_score": 2.18,
"quality_flag": "ok",
"source_reference": "Ada Lovelace",
"notes": "Ada Lovelace",
},
{
// type code here for "relation_one" field
"observed_at": new Date(Date.now()),
"raw_value": 7.19,
"normalized_value": 1.78,
"change_1d": 5.12,
"change_5d": 8.45,
"z_score": 8.99,
"quality_flag": "outlier",
"source_reference": "Ada Lovelace",
"notes": "Grace Hopper",
},
{
// type code here for "relation_one" field
"observed_at": new Date(Date.now()),
"raw_value": 1.12,
"normalized_value": 6.74,
"change_1d": 5.05,
"change_5d": 7.85,
"z_score": 0.23,
"quality_flag": "stale",
"source_reference": "Grace Hopper",
"notes": "Ada Lovelace",
},
];
const RegimeModelsData = [
{
"name": "Ada Lovelace",
"model_type": "ml",
"version": "Marie Curie",
"is_active": false,
"description": "Ada Lovelace",
"config_json": "Alan Turing",
// type code here for "relation_one" field
},
{
"name": "Grace Hopper",
"model_type": "rules_based",
"version": "Marie Curie",
"is_active": false,
"description": "Alan Turing",
"config_json": "Ada Lovelace",
// type code here for "relation_one" field
},
{
"name": "Ada Lovelace",
"model_type": "rules_based",
"version": "Alan Turing",
"is_active": false,
"description": "Grace Hopper",
"config_json": "Marie Curie",
// type code here for "relation_one" field
},
{
"name": "Alan Turing",
"model_type": "ml",
"version": "Grace Hopper",
"is_active": false,
"description": "Grace Hopper",
"config_json": "Grace Hopper",
// type code here for "relation_one" field
},
];
const RegimeRulesData = [
{
// type code here for "relation_one" field
"name": "Grace Hopper",
"target_regime": "inflation",
"priority": 7,
"is_enabled": true,
"logic_text": "Marie Curie",
"explanation_template": "Ada Lovelace",
},
{
// type code here for "relation_one" field
"name": "Grace Hopper",
"target_regime": "inflation",
"priority": 5,
"is_enabled": false,
"logic_text": "Grace Hopper",
"explanation_template": "Alan Turing",
},
{
// type code here for "relation_one" field
"name": "Ada Lovelace",
"target_regime": "growth",
"priority": 6,
"is_enabled": true,
"logic_text": "Alan Turing",
"explanation_template": "Alan Turing",
},
{
// type code here for "relation_one" field
"name": "Ada Lovelace",
"target_regime": "tightening",
"priority": 3,
"is_enabled": false,
"logic_text": "Alan Turing",
"explanation_template": "Marie Curie",
},
];
const RegimeDetectionsData = [
{
// type code here for "relation_one" field
"detected_at": new Date(Date.now()),
"regime": "growth",
"confidence": 9.53,
"explanation": "Alan Turing",
"growth_score": 2.45,
"inflation_score": 5.02,
"tightening_score": 8.99,
"stress_score": 7.26,
"inputs_snapshot_json": "Marie Curie",
"data_status": "live",
},
{
// type code here for "relation_one" field
"detected_at": new Date(Date.now()),
"regime": "growth",
"confidence": 1.59,
"explanation": "Grace Hopper",
"growth_score": 1.87,
"inflation_score": 0.33,
"tightening_score": 1.12,
"stress_score": 8.02,
"inputs_snapshot_json": "Alan Turing",
"data_status": "live",
},
{
// type code here for "relation_one" field
"detected_at": new Date(Date.now()),
"regime": "tightening",
"confidence": 2.85,
"explanation": "Grace Hopper",
"growth_score": 6.41,
"inflation_score": 4.58,
"tightening_score": 6.37,
"stress_score": 6.42,
"inputs_snapshot_json": "Grace Hopper",
"data_status": "demo",
},
{
// type code here for "relation_one" field
"detected_at": new Date(Date.now()),
"regime": "market_stress",
"confidence": 4.14,
"explanation": "Ada Lovelace",
"growth_score": 0.2,
"inflation_score": 8.55,
"tightening_score": 1.68,
"stress_score": 4.19,
"inputs_snapshot_json": "Marie Curie",
"data_status": "partial",
},
];
const AssetUniverseData = [
{
"name": "Alan Turing",
"symbol": "Alan Turing",
"asset_class": "crypto",
"risk_bucket": "defensive",
"currency": "Ada Lovelace",
// type code here for "relation_one" field
"is_enabled": false,
"description": "Grace Hopper",
},
{
"name": "Ada Lovelace",
"symbol": "Alan Turing",
"asset_class": "equities",
"risk_bucket": "growth",
"currency": "Ada Lovelace",
// type code here for "relation_one" field
"is_enabled": true,
"description": "Marie Curie",
},
{
"name": "Alan Turing",
"symbol": "Alan Turing",
"asset_class": "alternatives",
"risk_bucket": "balanced",
"currency": "Marie Curie",
// type code here for "relation_one" field
"is_enabled": true,
"description": "Ada Lovelace",
},
{
"name": "Ada Lovelace",
"symbol": "Alan Turing",
"asset_class": "cash",
"risk_bucket": "balanced",
"currency": "Grace Hopper",
// type code here for "relation_one" field
"is_enabled": true,
"description": "Ada Lovelace",
},
];
const PortfoliosData = [
{
// type code here for "relation_one" field
"name": "Ada Lovelace",
"description": "Ada Lovelace",
"risk_profile": "balanced",
"base_currency": "Marie Curie",
"is_default": true,
"inception_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"name": "Alan Turing",
"description": "Ada Lovelace",
"risk_profile": "conservative",
"base_currency": "Marie Curie",
"is_default": false,
"inception_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"name": "Marie Curie",
"description": "Grace Hopper",
"risk_profile": "growth",
"base_currency": "Marie Curie",
"is_default": true,
"inception_at": new Date(Date.now()),
},
{
// type code here for "relation_one" field
"name": "Marie Curie",
"description": "Ada Lovelace",
"risk_profile": "moderate",
"base_currency": "Marie Curie",
"is_default": false,
"inception_at": new Date(Date.now()),
},
];
const PortfolioPositionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"target_weight": 4.95,
"current_weight": 5.68,
"min_weight": 1.44,
"max_weight": 0.61,
"is_locked": true,
"notes": "Ada Lovelace",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"target_weight": 8.61,
"current_weight": 7.94,
"min_weight": 7.08,
"max_weight": 7.04,
"is_locked": true,
"notes": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"target_weight": 4.67,
"current_weight": 7.56,
"min_weight": 0.02,
"max_weight": 4.35,
"is_locked": false,
"notes": "Alan Turing",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"target_weight": 6.47,
"current_weight": 6.84,
"min_weight": 5.08,
"max_weight": 0.1,
"is_locked": true,
"notes": "Grace Hopper",
},
];
const AllocationPoliciesData = [
{
"name": "Alan Turing",
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_active": false,
"description": "Alan Turing",
},
{
"name": "Alan Turing",
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_active": false,
"description": "Grace Hopper",
},
{
"name": "Grace Hopper",
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_active": true,
"description": "Ada Lovelace",
},
{
"name": "Grace Hopper",
// type code here for "relation_one" field
// type code here for "relation_one" field
"is_active": true,
"description": "Ada Lovelace",
},
];
const RegimeAllocationsData = [
{
// type code here for "relation_one" field
"regime": "tightening",
// type code here for "relation_one" field
"target_weight": 1.58,
"tilt_strength": 4.77,
"rationale": "Ada Lovelace",
},
{
// type code here for "relation_one" field
"regime": "growth",
// type code here for "relation_one" field
"target_weight": 5.66,
"tilt_strength": 9.51,
"rationale": "Grace Hopper",
},
{
// type code here for "relation_one" field
"regime": "inflation",
// type code here for "relation_one" field
"target_weight": 1.46,
"tilt_strength": 1.61,
"rationale": "Grace Hopper",
},
{
// type code here for "relation_one" field
"regime": "market_stress",
// type code here for "relation_one" field
"target_weight": 2.71,
"tilt_strength": 3.91,
"rationale": "Ada Lovelace",
},
];
const RebalancingRecommendationsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"generated_at": new Date(Date.now()),
"status": "draft",
"expected_risk_change": 8.9,
"expected_return_change": 8.44,
"turnover_estimate": 1.45,
"summary": "Marie Curie",
"details_json": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"generated_at": new Date(Date.now()),
"status": "published",
"expected_risk_change": 0.87,
"expected_return_change": 9.16,
"turnover_estimate": 7.23,
"summary": "Marie Curie",
"details_json": "Ada Lovelace",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"generated_at": new Date(Date.now()),
"status": "archived",
"expected_risk_change": 6.22,
"expected_return_change": 9.45,
"turnover_estimate": 6.89,
"summary": "Alan Turing",
"details_json": "Grace Hopper",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"generated_at": new Date(Date.now()),
"status": "archived",
"expected_risk_change": 4.05,
"expected_return_change": 5.79,
"turnover_estimate": 6.16,
"summary": "Ada Lovelace",
"details_json": "Ada Lovelace",
},
];
const FetchJobsData = [
{
// type code here for "relation_one" field
"name": "Marie Curie",
"job_type": "asset_price_fetch",
"schedule_type": "hourly",
"next_run_at": new Date(Date.now()),
"last_run_at": new Date(Date.now()),
"last_status": "failed",
"retry_count": 4,
"last_error": "Grace Hopper",
"is_enabled": true,
},
{
// type code here for "relation_one" field
"name": "Marie Curie",
"job_type": "regime_run",
"schedule_type": "manual",
"next_run_at": new Date(Date.now()),
"last_run_at": new Date(Date.now()),
"last_status": "partial",
"retry_count": 1,
"last_error": "Ada Lovelace",
"is_enabled": true,
},
{
// type code here for "relation_one" field
"name": "Ada Lovelace",
"job_type": "asset_price_fetch",
"schedule_type": "manual",
"next_run_at": new Date(Date.now()),
"last_run_at": new Date(Date.now()),
"last_status": "running",
"retry_count": 7,
"last_error": "Ada Lovelace",
"is_enabled": true,
},
{
// type code here for "relation_one" field
"name": "Grace Hopper",
"job_type": "asset_price_fetch",
"schedule_type": "daily",
"next_run_at": new Date(Date.now()),
"last_run_at": new Date(Date.now()),
"last_status": "failed",
"retry_count": 8,
"last_error": "Grace Hopper",
"is_enabled": false,
},
];
const JobRunsData = [
{
// type code here for "relation_one" field
"started_at": new Date(Date.now()),
"finished_at": new Date(Date.now()),
"status": "success",
"records_fetched": 5,
"records_written": 8,
"log_text": "Grace Hopper",
"error_text": "Ada Lovelace",
},
{
// type code here for "relation_one" field
"started_at": new Date(Date.now()),
"finished_at": new Date(Date.now()),
"status": "running",
"records_fetched": 7,
"records_written": 1,
"log_text": "Alan Turing",
"error_text": "Alan Turing",
},
{
// type code here for "relation_one" field
"started_at": new Date(Date.now()),
"finished_at": new Date(Date.now()),
"status": "success",
"records_fetched": 4,
"records_written": 9,
"log_text": "Alan Turing",
"error_text": "Ada Lovelace",
},
{
// type code here for "relation_one" field
"started_at": new Date(Date.now()),
"finished_at": new Date(Date.now()),
"status": "running",
"records_fetched": 5,
"records_written": 3,
"log_text": "Grace Hopper",
"error_text": "Marie Curie",
},
];
// Similar logic for "relation_many"
async function associateApiCredentialWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiCredential0 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ApiCredential0?.setUser)
{
await
ApiCredential0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiCredential1 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ApiCredential1?.setUser)
{
await
ApiCredential1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiCredential2 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ApiCredential2?.setUser)
{
await
ApiCredential2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiCredential3 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ApiCredential3?.setUser)
{
await
ApiCredential3.
setUser(relatedUser3);
}
}
async function associateApiCredentialWithData_provider() {
const relatedData_provider0 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const ApiCredential0 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ApiCredential0?.setData_provider)
{
await
ApiCredential0.
setData_provider(relatedData_provider0);
}
const relatedData_provider1 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const ApiCredential1 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ApiCredential1?.setData_provider)
{
await
ApiCredential1.
setData_provider(relatedData_provider1);
}
const relatedData_provider2 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const ApiCredential2 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ApiCredential2?.setData_provider)
{
await
ApiCredential2.
setData_provider(relatedData_provider2);
}
const relatedData_provider3 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const ApiCredential3 = await ApiCredentials.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ApiCredential3?.setData_provider)
{
await
ApiCredential3.
setData_provider(relatedData_provider3);
}
}
async function associateMarketIndicatorWithData_provider() {
const relatedData_provider0 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const MarketIndicator0 = await MarketIndicators.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (MarketIndicator0?.setData_provider)
{
await
MarketIndicator0.
setData_provider(relatedData_provider0);
}
const relatedData_provider1 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const MarketIndicator1 = await MarketIndicators.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (MarketIndicator1?.setData_provider)
{
await
MarketIndicator1.
setData_provider(relatedData_provider1);
}
const relatedData_provider2 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const MarketIndicator2 = await MarketIndicators.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (MarketIndicator2?.setData_provider)
{
await
MarketIndicator2.
setData_provider(relatedData_provider2);
}
const relatedData_provider3 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const MarketIndicator3 = await MarketIndicators.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (MarketIndicator3?.setData_provider)
{
await
MarketIndicator3.
setData_provider(relatedData_provider3);
}
}
async function associateIndicatorObservationWithMarket_indicator() {
const relatedMarket_indicator0 = await MarketIndicators.findOne({
offset: Math.floor(Math.random() * (await MarketIndicators.count())),
});
const IndicatorObservation0 = await IndicatorObservations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (IndicatorObservation0?.setMarket_indicator)
{
await
IndicatorObservation0.
setMarket_indicator(relatedMarket_indicator0);
}
const relatedMarket_indicator1 = await MarketIndicators.findOne({
offset: Math.floor(Math.random() * (await MarketIndicators.count())),
});
const IndicatorObservation1 = await IndicatorObservations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (IndicatorObservation1?.setMarket_indicator)
{
await
IndicatorObservation1.
setMarket_indicator(relatedMarket_indicator1);
}
const relatedMarket_indicator2 = await MarketIndicators.findOne({
offset: Math.floor(Math.random() * (await MarketIndicators.count())),
});
const IndicatorObservation2 = await IndicatorObservations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (IndicatorObservation2?.setMarket_indicator)
{
await
IndicatorObservation2.
setMarket_indicator(relatedMarket_indicator2);
}
const relatedMarket_indicator3 = await MarketIndicators.findOne({
offset: Math.floor(Math.random() * (await MarketIndicators.count())),
});
const IndicatorObservation3 = await IndicatorObservations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (IndicatorObservation3?.setMarket_indicator)
{
await
IndicatorObservation3.
setMarket_indicator(relatedMarket_indicator3);
}
}
async function associateRegimeModelWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const RegimeModel0 = await RegimeModels.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RegimeModel0?.setOwner)
{
await
RegimeModel0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const RegimeModel1 = await RegimeModels.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RegimeModel1?.setOwner)
{
await
RegimeModel1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const RegimeModel2 = await RegimeModels.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RegimeModel2?.setOwner)
{
await
RegimeModel2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const RegimeModel3 = await RegimeModels.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RegimeModel3?.setOwner)
{
await
RegimeModel3.
setOwner(relatedOwner3);
}
}
async function associateRegimeRuleWithRegime_model() {
const relatedRegime_model0 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeRule0 = await RegimeRules.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RegimeRule0?.setRegime_model)
{
await
RegimeRule0.
setRegime_model(relatedRegime_model0);
}
const relatedRegime_model1 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeRule1 = await RegimeRules.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RegimeRule1?.setRegime_model)
{
await
RegimeRule1.
setRegime_model(relatedRegime_model1);
}
const relatedRegime_model2 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeRule2 = await RegimeRules.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RegimeRule2?.setRegime_model)
{
await
RegimeRule2.
setRegime_model(relatedRegime_model2);
}
const relatedRegime_model3 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeRule3 = await RegimeRules.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RegimeRule3?.setRegime_model)
{
await
RegimeRule3.
setRegime_model(relatedRegime_model3);
}
}
async function associateRegimeDetectionWithRegime_model() {
const relatedRegime_model0 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeDetection0 = await RegimeDetections.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RegimeDetection0?.setRegime_model)
{
await
RegimeDetection0.
setRegime_model(relatedRegime_model0);
}
const relatedRegime_model1 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeDetection1 = await RegimeDetections.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RegimeDetection1?.setRegime_model)
{
await
RegimeDetection1.
setRegime_model(relatedRegime_model1);
}
const relatedRegime_model2 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeDetection2 = await RegimeDetections.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RegimeDetection2?.setRegime_model)
{
await
RegimeDetection2.
setRegime_model(relatedRegime_model2);
}
const relatedRegime_model3 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const RegimeDetection3 = await RegimeDetections.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RegimeDetection3?.setRegime_model)
{
await
RegimeDetection3.
setRegime_model(relatedRegime_model3);
}
}
async function associateAssetUniverseWithData_provider() {
const relatedData_provider0 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const AssetUniverse0 = await AssetUniverse.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AssetUniverse0?.setData_provider)
{
await
AssetUniverse0.
setData_provider(relatedData_provider0);
}
const relatedData_provider1 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const AssetUniverse1 = await AssetUniverse.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AssetUniverse1?.setData_provider)
{
await
AssetUniverse1.
setData_provider(relatedData_provider1);
}
const relatedData_provider2 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const AssetUniverse2 = await AssetUniverse.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AssetUniverse2?.setData_provider)
{
await
AssetUniverse2.
setData_provider(relatedData_provider2);
}
const relatedData_provider3 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const AssetUniverse3 = await AssetUniverse.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AssetUniverse3?.setData_provider)
{
await
AssetUniverse3.
setData_provider(relatedData_provider3);
}
}
async function associatePortfolioWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Portfolio0 = await Portfolios.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Portfolio0?.setOwner)
{
await
Portfolio0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Portfolio1 = await Portfolios.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Portfolio1?.setOwner)
{
await
Portfolio1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Portfolio2 = await Portfolios.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Portfolio2?.setOwner)
{
await
Portfolio2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Portfolio3 = await Portfolios.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Portfolio3?.setOwner)
{
await
Portfolio3.
setOwner(relatedOwner3);
}
}
async function associatePortfolioPositionWithPortfolio() {
const relatedPortfolio0 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const PortfolioPosition0 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PortfolioPosition0?.setPortfolio)
{
await
PortfolioPosition0.
setPortfolio(relatedPortfolio0);
}
const relatedPortfolio1 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const PortfolioPosition1 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PortfolioPosition1?.setPortfolio)
{
await
PortfolioPosition1.
setPortfolio(relatedPortfolio1);
}
const relatedPortfolio2 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const PortfolioPosition2 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PortfolioPosition2?.setPortfolio)
{
await
PortfolioPosition2.
setPortfolio(relatedPortfolio2);
}
const relatedPortfolio3 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const PortfolioPosition3 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (PortfolioPosition3?.setPortfolio)
{
await
PortfolioPosition3.
setPortfolio(relatedPortfolio3);
}
}
async function associatePortfolioPositionWithAsset() {
const relatedAsset0 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const PortfolioPosition0 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PortfolioPosition0?.setAsset)
{
await
PortfolioPosition0.
setAsset(relatedAsset0);
}
const relatedAsset1 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const PortfolioPosition1 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PortfolioPosition1?.setAsset)
{
await
PortfolioPosition1.
setAsset(relatedAsset1);
}
const relatedAsset2 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const PortfolioPosition2 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PortfolioPosition2?.setAsset)
{
await
PortfolioPosition2.
setAsset(relatedAsset2);
}
const relatedAsset3 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const PortfolioPosition3 = await PortfolioPositions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (PortfolioPosition3?.setAsset)
{
await
PortfolioPosition3.
setAsset(relatedAsset3);
}
}
async function associateAllocationPolicyWithPortfolio() {
const relatedPortfolio0 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const AllocationPolicy0 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AllocationPolicy0?.setPortfolio)
{
await
AllocationPolicy0.
setPortfolio(relatedPortfolio0);
}
const relatedPortfolio1 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const AllocationPolicy1 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AllocationPolicy1?.setPortfolio)
{
await
AllocationPolicy1.
setPortfolio(relatedPortfolio1);
}
const relatedPortfolio2 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const AllocationPolicy2 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AllocationPolicy2?.setPortfolio)
{
await
AllocationPolicy2.
setPortfolio(relatedPortfolio2);
}
const relatedPortfolio3 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const AllocationPolicy3 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AllocationPolicy3?.setPortfolio)
{
await
AllocationPolicy3.
setPortfolio(relatedPortfolio3);
}
}
async function associateAllocationPolicyWithRegime_model() {
const relatedRegime_model0 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const AllocationPolicy0 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AllocationPolicy0?.setRegime_model)
{
await
AllocationPolicy0.
setRegime_model(relatedRegime_model0);
}
const relatedRegime_model1 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const AllocationPolicy1 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AllocationPolicy1?.setRegime_model)
{
await
AllocationPolicy1.
setRegime_model(relatedRegime_model1);
}
const relatedRegime_model2 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const AllocationPolicy2 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AllocationPolicy2?.setRegime_model)
{
await
AllocationPolicy2.
setRegime_model(relatedRegime_model2);
}
const relatedRegime_model3 = await RegimeModels.findOne({
offset: Math.floor(Math.random() * (await RegimeModels.count())),
});
const AllocationPolicy3 = await AllocationPolicies.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AllocationPolicy3?.setRegime_model)
{
await
AllocationPolicy3.
setRegime_model(relatedRegime_model3);
}
}
async function associateRegimeAllocationWithAllocation_policy() {
const relatedAllocation_policy0 = await AllocationPolicies.findOne({
offset: Math.floor(Math.random() * (await AllocationPolicies.count())),
});
const RegimeAllocation0 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RegimeAllocation0?.setAllocation_policy)
{
await
RegimeAllocation0.
setAllocation_policy(relatedAllocation_policy0);
}
const relatedAllocation_policy1 = await AllocationPolicies.findOne({
offset: Math.floor(Math.random() * (await AllocationPolicies.count())),
});
const RegimeAllocation1 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RegimeAllocation1?.setAllocation_policy)
{
await
RegimeAllocation1.
setAllocation_policy(relatedAllocation_policy1);
}
const relatedAllocation_policy2 = await AllocationPolicies.findOne({
offset: Math.floor(Math.random() * (await AllocationPolicies.count())),
});
const RegimeAllocation2 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RegimeAllocation2?.setAllocation_policy)
{
await
RegimeAllocation2.
setAllocation_policy(relatedAllocation_policy2);
}
const relatedAllocation_policy3 = await AllocationPolicies.findOne({
offset: Math.floor(Math.random() * (await AllocationPolicies.count())),
});
const RegimeAllocation3 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RegimeAllocation3?.setAllocation_policy)
{
await
RegimeAllocation3.
setAllocation_policy(relatedAllocation_policy3);
}
}
async function associateRegimeAllocationWithAsset() {
const relatedAsset0 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const RegimeAllocation0 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RegimeAllocation0?.setAsset)
{
await
RegimeAllocation0.
setAsset(relatedAsset0);
}
const relatedAsset1 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const RegimeAllocation1 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RegimeAllocation1?.setAsset)
{
await
RegimeAllocation1.
setAsset(relatedAsset1);
}
const relatedAsset2 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const RegimeAllocation2 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RegimeAllocation2?.setAsset)
{
await
RegimeAllocation2.
setAsset(relatedAsset2);
}
const relatedAsset3 = await AssetUniverse.findOne({
offset: Math.floor(Math.random() * (await AssetUniverse.count())),
});
const RegimeAllocation3 = await RegimeAllocations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RegimeAllocation3?.setAsset)
{
await
RegimeAllocation3.
setAsset(relatedAsset3);
}
}
async function associateRebalancingRecommendationWithPortfolio() {
const relatedPortfolio0 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const RebalancingRecommendation0 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RebalancingRecommendation0?.setPortfolio)
{
await
RebalancingRecommendation0.
setPortfolio(relatedPortfolio0);
}
const relatedPortfolio1 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const RebalancingRecommendation1 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RebalancingRecommendation1?.setPortfolio)
{
await
RebalancingRecommendation1.
setPortfolio(relatedPortfolio1);
}
const relatedPortfolio2 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const RebalancingRecommendation2 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RebalancingRecommendation2?.setPortfolio)
{
await
RebalancingRecommendation2.
setPortfolio(relatedPortfolio2);
}
const relatedPortfolio3 = await Portfolios.findOne({
offset: Math.floor(Math.random() * (await Portfolios.count())),
});
const RebalancingRecommendation3 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RebalancingRecommendation3?.setPortfolio)
{
await
RebalancingRecommendation3.
setPortfolio(relatedPortfolio3);
}
}
async function associateRebalancingRecommendationWithRegime_detection() {
const relatedRegime_detection0 = await RegimeDetections.findOne({
offset: Math.floor(Math.random() * (await RegimeDetections.count())),
});
const RebalancingRecommendation0 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (RebalancingRecommendation0?.setRegime_detection)
{
await
RebalancingRecommendation0.
setRegime_detection(relatedRegime_detection0);
}
const relatedRegime_detection1 = await RegimeDetections.findOne({
offset: Math.floor(Math.random() * (await RegimeDetections.count())),
});
const RebalancingRecommendation1 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (RebalancingRecommendation1?.setRegime_detection)
{
await
RebalancingRecommendation1.
setRegime_detection(relatedRegime_detection1);
}
const relatedRegime_detection2 = await RegimeDetections.findOne({
offset: Math.floor(Math.random() * (await RegimeDetections.count())),
});
const RebalancingRecommendation2 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (RebalancingRecommendation2?.setRegime_detection)
{
await
RebalancingRecommendation2.
setRegime_detection(relatedRegime_detection2);
}
const relatedRegime_detection3 = await RegimeDetections.findOne({
offset: Math.floor(Math.random() * (await RegimeDetections.count())),
});
const RebalancingRecommendation3 = await RebalancingRecommendations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (RebalancingRecommendation3?.setRegime_detection)
{
await
RebalancingRecommendation3.
setRegime_detection(relatedRegime_detection3);
}
}
async function associateFetchJobWithData_provider() {
const relatedData_provider0 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const FetchJob0 = await FetchJobs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (FetchJob0?.setData_provider)
{
await
FetchJob0.
setData_provider(relatedData_provider0);
}
const relatedData_provider1 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const FetchJob1 = await FetchJobs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (FetchJob1?.setData_provider)
{
await
FetchJob1.
setData_provider(relatedData_provider1);
}
const relatedData_provider2 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const FetchJob2 = await FetchJobs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (FetchJob2?.setData_provider)
{
await
FetchJob2.
setData_provider(relatedData_provider2);
}
const relatedData_provider3 = await DataProviders.findOne({
offset: Math.floor(Math.random() * (await DataProviders.count())),
});
const FetchJob3 = await FetchJobs.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (FetchJob3?.setData_provider)
{
await
FetchJob3.
setData_provider(relatedData_provider3);
}
}
async function associateJobRunWithFetch_job() {
const relatedFetch_job0 = await FetchJobs.findOne({
offset: Math.floor(Math.random() * (await FetchJobs.count())),
});
const JobRun0 = await JobRuns.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (JobRun0?.setFetch_job)
{
await
JobRun0.
setFetch_job(relatedFetch_job0);
}
const relatedFetch_job1 = await FetchJobs.findOne({
offset: Math.floor(Math.random() * (await FetchJobs.count())),
});
const JobRun1 = await JobRuns.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (JobRun1?.setFetch_job)
{
await
JobRun1.
setFetch_job(relatedFetch_job1);
}
const relatedFetch_job2 = await FetchJobs.findOne({
offset: Math.floor(Math.random() * (await FetchJobs.count())),
});
const JobRun2 = await JobRuns.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (JobRun2?.setFetch_job)
{
await
JobRun2.
setFetch_job(relatedFetch_job2);
}
const relatedFetch_job3 = await FetchJobs.findOne({
offset: Math.floor(Math.random() * (await FetchJobs.count())),
});
const JobRun3 = await JobRuns.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (JobRun3?.setFetch_job)
{
await
JobRun3.
setFetch_job(relatedFetch_job3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await DataProviders.bulkCreate(DataProvidersData);
await ApiCredentials.bulkCreate(ApiCredentialsData);
await MarketIndicators.bulkCreate(MarketIndicatorsData);
await IndicatorObservations.bulkCreate(IndicatorObservationsData);
await RegimeModels.bulkCreate(RegimeModelsData);
await RegimeRules.bulkCreate(RegimeRulesData);
await RegimeDetections.bulkCreate(RegimeDetectionsData);
await AssetUniverse.bulkCreate(AssetUniverseData);
await Portfolios.bulkCreate(PortfoliosData);
await PortfolioPositions.bulkCreate(PortfolioPositionsData);
await AllocationPolicies.bulkCreate(AllocationPoliciesData);
await RegimeAllocations.bulkCreate(RegimeAllocationsData);
await RebalancingRecommendations.bulkCreate(RebalancingRecommendationsData);
await FetchJobs.bulkCreate(FetchJobsData);
await JobRuns.bulkCreate(JobRunsData);
await Promise.all([
// Similar logic for "relation_many"
await associateApiCredentialWithUser(),
await associateApiCredentialWithData_provider(),
await associateMarketIndicatorWithData_provider(),
await associateIndicatorObservationWithMarket_indicator(),
await associateRegimeModelWithOwner(),
await associateRegimeRuleWithRegime_model(),
await associateRegimeDetectionWithRegime_model(),
await associateAssetUniverseWithData_provider(),
await associatePortfolioWithOwner(),
await associatePortfolioPositionWithPortfolio(),
await associatePortfolioPositionWithAsset(),
await associateAllocationPolicyWithPortfolio(),
await associateAllocationPolicyWithRegime_model(),
await associateRegimeAllocationWithAllocation_policy(),
await associateRegimeAllocationWithAsset(),
await associateRebalancingRecommendationWithPortfolio(),
await associateRebalancingRecommendationWithRegime_detection(),
await associateFetchJobWithData_provider(),
await associateJobRunWithFetch_job(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('data_providers', null, {});
await queryInterface.bulkDelete('api_credentials', null, {});
await queryInterface.bulkDelete('market_indicators', null, {});
await queryInterface.bulkDelete('indicator_observations', null, {});
await queryInterface.bulkDelete('regime_models', null, {});
await queryInterface.bulkDelete('regime_rules', null, {});
await queryInterface.bulkDelete('regime_detections', null, {});
await queryInterface.bulkDelete('asset_universe', null, {});
await queryInterface.bulkDelete('portfolios', null, {});
await queryInterface.bulkDelete('portfolio_positions', null, {});
await queryInterface.bulkDelete('allocation_policies', null, {});
await queryInterface.bulkDelete('regime_allocations', null, {});
await queryInterface.bulkDelete('rebalancing_recommendations', null, {});
await queryInterface.bulkDelete('fetch_jobs', null, {});
await queryInterface.bulkDelete('job_runs', null, {});
},
};