LPF and Prices
const START_DATE = new Date(2010, 6, 18);
function computeLPF(daysFromStart) {
const ALPHA = 1.0311;
const BETA = -7.1874;
let dateToday = 1 + daysFromStart;
let rootDate = Math.cbrt(dateToday);
return Math.exp(ALPHA * rootDate + BETA);
}
function generateLPFData() {
let today = new Date();
let daysElapsedToday = Math.floor((today - START_DATE) / (1000 * 60 * 60 * 24));
let currentDate = new Date(START_DATE);
let dataPoints = [];
for (let t = 0; t <= daysElapsedToday; t++) {
let lpfValue = computeLPF(t);
dataPoints.push({ x: currentDate, y: lpfValue });
currentDate = new Date(currentDate.valueOf() + 24 * 60 * 60 * 1000); // Increment by one day
}
return dataPoints;
}
var chart = new CanvasJS.StockChart("chartContainer", {
animationEnabled: true,
zoomEnabled: true,
theme: "light2",
// backgroundColor: "#000000",
// legend: {
// fontColor: "#FFFFFF" // This sets the legend text color to white
// },
title: {
// text: "LPF Value and Bitcoin Price over Time"
},
charts: [{
axisX: {
// title: "Date",
valueFormatString: "D MMM YYYY",
// lineColor: "#383838", // Custom Line Color for X-axis
// labelFontColor: "#3366FF" // Custom Label Color for X-axis
},
axisY: {
logarithmic: true,
title: "USD Value, log scale",
// titleFontColor: "#FFFFFF",
titleFontSize: 18, // Set the font size here
// lineColor: "#383838",
// labelFontColor: "#3366FF",
gridThickness: 0,
lineThickness: 1
},
data: [{
type: "line",
// color: "#00BEFF",
showInLegend: true,
name: "LPF Value",
xValueType: "dateTime",
xValueFormatString: "D MMM YYYY",
yValueFormatString: "####.0000",
dataPoints: generateLPFData()
}]
}],
navigator: {
slider: {
minimum: new Date(2010, 6, 18),
maximum: new Date()
}
}
});
function fetchBitcoinPrices() {
fetch('https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?assets=btc&metrics=PriceUSD&frequency=1d&page_size=10000')
.then(response => response.json())
.then(data => {
if (data && data.data) {
const bitcoinPrices = data.data.map(entry => {
return {
x: new Date(entry.time), // Parse the ISO date string
y: parseFloat(entry.PriceUSD) // Convert the price to a floating point number
};
});
// Check if the chart has a data series for Bitcoin prices
let bitcoinSeries = chart.options.charts[0].data.find(series => series.name === "Price");
if (bitcoinSeries) {
// Update existing series
bitcoinSeries.dataPoints = bitcoinPrices;
} else {
// Add new series
chart.options.charts[0].data.push({
type: "line",
name: "Price",
showInLegend: true,
xValueType: "dateTime",
xValueFormatString: "D MMM YYYY",
yValueFormatString: "$###0.00",
dataPoints: bitcoinPrices
});
}
chart.render();
} else {
console.error('No data received from CoinMetrics API');
}
})
.catch(error => console.error('Error fetching data from CoinMetrics:', error));
}
fetchBitcoinPrices();
chart.render();
const totalDays = Math.floor((new Date() - START_DATE) / (1000 * 60 * 60 * 24));
//document.getElementById('dateRangeSlider').max = totalDays - 7; // Ensuring at least 7 days can be selected
//document.getElementById('windowSizeSlider').max = totalDays;
const START_DATE = new Date(2010, 6, 18);
function computeLPF(daysFromStart) {
const ALPHA = 1.0311;
const BETA = -7.1874;
let dateToday = 1 + daysFromStart;
let rootDate = Math.cbrt(dateToday);
return Math.exp(ALPHA * rootDate + BETA);
}
function generateLPFData() {
let today = new Date();
let daysElapsedToday = Math.floor((today - START_DATE) / (1000 * 60 * 60 * 24));
let currentDate = new Date(START_DATE);
let dataPoints = [];
for (let t = 0; t <= daysElapsedToday; t++) {
let lpfValue = computeLPF(t);
dataPoints.push({ x: currentDate, y: lpfValue });
currentDate = new Date(currentDate.valueOf() + 24 * 60 * 60 * 1000); // Increment by one day
}
return dataPoints;
}
var chart = new CanvasJS.StockChart("chartContainer", {
animationEnabled: true,
zoomEnabled: true,
theme: "light2",
// backgroundColor: "#000000",
// legend: {
// fontColor: "#FFFFFF" // This sets the legend text color to white
// },
title: {
// text: "LPF Value and Bitcoin Price over Time"
},
charts: [{
axisX: {
// title: "Date",
valueFormatString: "D MMM YYYY",
// lineColor: "#383838", // Custom Line Color for X-axis
// labelFontColor: "#3366FF" // Custom Label Color for X-axis
},
axisY: {
logarithmic: true,
title: "USD Value, log scale",
// titleFontColor: "#FFFFFF",
titleFontSize: 18, // Set the font size here
// lineColor: "#383838",
// labelFontColor: "#3366FF",
gridThickness: 0,
lineThickness: 1
},
data: [{
type: "line",
// color: "#00BEFF",
showInLegend: true,
name: "LPF Value",
xValueType: "dateTime",
xValueFormatString: "D MMM YYYY",
yValueFormatString: "####.0000",
dataPoints: generateLPFData()
}]
}],
navigator: {
slider: {
minimum: new Date(2010, 6, 18),
maximum: new Date()
}
}
});
function fetchBitcoinPrices() {
fetch('https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?assets=btc&metrics=PriceUSD&frequency=1d&page_size=10000')
.then(response => response.json())
.then(data => {
if (data && data.data) {
const bitcoinPrices = data.data.map(entry => {
return {
x: new Date(entry.time), // Parse the ISO date string
y: parseFloat(entry.PriceUSD) // Convert the price to a floating point number
};
});
// Check if the chart has a data series for Bitcoin prices
let bitcoinSeries = chart.options.charts[0].data.find(series => series.name === "Price");
if (bitcoinSeries) {
// Update existing series
bitcoinSeries.dataPoints = bitcoinPrices;
} else {
// Add new series
chart.options.charts[0].data.push({
type: "line",
name: "Price",
showInLegend: true,
xValueType: "dateTime",
xValueFormatString: "D MMM YYYY",
yValueFormatString: "$###0.00",
dataPoints: bitcoinPrices
});
}
chart.render();
} else {
console.error('No data received from CoinMetrics API');
}
})
.catch(error => console.error('Error fetching data from CoinMetrics:', error));
}
fetchBitcoinPrices();
chart.render();
const totalDays = Math.floor((new Date() - START_DATE) / (1000 * 60 * 60 * 24));
//document.getElementById('dateRangeSlider').max = totalDays - 7; // Ensuring at least 7 days can be selected
//document.getElementById('windowSizeSlider').max = totalDays;