Published
Edited
Dec 9, 2019
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
dailyReturns = {
return dailyFlat[0].map((day, idx, arr) => {
let total = 0
if (!idx) {
let total = day.oneDayReturn * (day.totalSupplyInUSD / dailyTotalUsd[idx])
} else {
let total = day.oneDayReturn * (arr[idx-1].totalSupplyInUSD / dailyTotalUsd[idx-1])
}
for(let i=1; i < dailyFlat.length;i++) {
if (!idx) {
total += dailyFlat[i][idx].oneDayReturn * (dailyFlat[i][idx].totalSupplyInUSD / dailyTotalUsd[idx])
} else {
total += dailyFlat[i][idx].oneDayReturn * (dailyFlat[i][idx-1].totalSupplyInUSD / dailyTotalUsd[idx-1])
}
}
return total
})
}
Insert cell
Insert cell
comparisionChartData = ({
series: [
{ name: "Debt Pool Returns", values: returnIndex }
],
dates: dailyFlat[0].map(d => d.date.slice(0,10)).map(d3.timeParse("%Y-%m-%d"))
})
Insert cell
dailyFlat = synthReturns.map(s => s[1]).map(d => d.sort((a,b) => a.block - b.block))
Insert cell
synthReturns = Object.entries(synthJson).map(s => {
const data = s[1]
const returns = data.map((day, idx, arr) => {
if (!idx) {
day.oneDayReturn = 0
} else {
const previous = arr[idx-1].rateForSynth
day.oneDayReturn = (day.rateForSynth - previous) / previous
}
return day
})
return [s[0], returns.slice(-51)]
})
Insert cell
synthJson = d3.json(url)
Insert cell
url = 'https://gist.githubusercontent.com/bgits/f7f95503adb2da6cf83e64257f9c748b/raw/640a945c6316f7ad0324f4eb8f0cfa43f1dcc761/gistfile1.txt'
Insert cell
x = d3.scaleTime()
.domain(d3.extent(comparisionChartData.dates))
.range([margin.left, width - margin.right])
Insert cell
margin = ({top: 30, right:0, bottom: 30, left: 50})
Insert cell
y = d3.scaleLinear()
.domain([d3.min(comparisionChartData.series, d => d3.min(d.values)), d3.max(comparisionChartData.series, d => d3.max(d.values))]).nice()
.range([height - margin.bottom, margin.top])
Insert cell
height = 600
Insert cell
line = d3.line()
.defined(d => !isNaN(d))
.x((d, i) => x(comparisionChartData.dates[i]))
.y(d => y(d))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Hypothetical index"))
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
Insert cell
Insert cell
d3 = require('d3')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more