mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-27 17:19:39 +02:00
Build sample portfolio deterministically (#993)
This commit is contained in:
parent
e9f42c1a65
commit
ef0f910b9b
1 changed files with 14 additions and 3 deletions
|
@ -197,10 +197,21 @@ class Demo::Generator
|
||||||
balance: 100000,
|
balance: 100000,
|
||||||
institution: family.institutions.find_or_create_by(name: "Robinhood")
|
institution: family.institutions.find_or_create_by(name: "Robinhood")
|
||||||
|
|
||||||
15.times do
|
aapl = Security.find_by(symbol: "AAPL")
|
||||||
|
tm = Security.find_by(symbol: "TM")
|
||||||
|
msft = Security.find_by(symbol: "MSFT")
|
||||||
|
|
||||||
|
trades = [
|
||||||
|
{ security: aapl, qty: 20 }, { security: msft, qty: 10 }, { security: aapl, qty: -5 },
|
||||||
|
{ security: msft, qty: -5 }, { security: tm, qty: 10 }, { security: msft, qty: 5 },
|
||||||
|
{ security: tm, qty: 10 }, { security: aapl, qty: -5 }, { security: msft, qty: -5 },
|
||||||
|
{ security: tm, qty: 10 }, { security: msft, qty: 5 }, { security: aapl, qty: -10 }
|
||||||
|
]
|
||||||
|
|
||||||
|
trades.each do |trade|
|
||||||
date = Faker::Number.positive(to: 730).days.ago.to_date
|
date = Faker::Number.positive(to: 730).days.ago.to_date
|
||||||
security = securities.sample
|
security = trade[:security]
|
||||||
qty = Faker::Number.between(from: -10, to: 10)
|
qty = trade[:qty]
|
||||||
price = Security::Price.find_by!(isin: security.isin, date: date).price
|
price = Security::Price.find_by!(isin: security.isin, date: date).price
|
||||||
name_prefix = qty < 0 ? "Sell " : "Buy "
|
name_prefix = qty < 0 ? "Sell " : "Buy "
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue