Published
Edited
Mar 9, 2020
1 star
Insert cell
Insert cell
Insert cell
sac = ({
//"VOO": 0.20, // Vanguard S&P 500
"QQQ": 0.20, // NDX
"VNQ": 0.10, // Vanguard Real Estate
"LQD": 0.20, // iShare Corp Bonds
"IEF": 0.20, // iShare 1-5 Year Bounds
"TLT": 0.30, // iShare 5-10 Year Bounds
})
Insert cell
Insert cell
strategy = ({
period: 'everyMonth',
rolling: 0,
rebalance: (date, getPrice, order, portfolio) => {
const total = 200
for (const tick in sac) {
order(tick, total * sac[tick])
}
}
})
Insert cell
Insert cell
Insert cell
portfolio = {
const algo = new alg.Algo()
const data = new alg.Data()

await data.fetch(Object.keys(sac), moment(startDate).format("YYYY-MM-DD"))

const portfolio = algo.run(data, strategy)
return portfolio
}
Insert cell
Insert cell
Insert cell
portfolio.print().total
Insert cell
portfolio.print().perPeriod
Insert cell
portfolio.print().perTick
Insert cell
md`### Imports`
Insert cell
alg = require('stockant-algo@1.0.13/bundles/stockant-algo.js')
Insert cell
Insert cell
import {plot} from '@vega/vega-plot';
Insert cell
Insert cell
html`<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">`
Insert cell
html`
<style type="text/css">.custom-font { font-family: 'Roboto'; }</style>
<h2 class="custom-font">Roboto Font</h2>
`
Insert cell
moment = require("moment")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more