This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
#load data from your preferred source | |
data = pd.read_csv("PATH/TO/FILE/futures_rolling.csv", index_col = [0], parse_dates=True) | |
june_21 = data["VX-2021M"] | |
july_21 = data["VX-2021N"] | |
def perpetual_rollover(previous_futures, next_futures, roll_date, number_of_rolls): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
#load data from your preferred source | |
data = pd.read_csv("PATH/TO/FILE/futures_rolling.csv", index_col = [0], parse_dates=True) | |
june_21 = data["VX-2021M"] | |
july_21 = data["VX-2021N"] | |
def proportional_adjustment(previous_futures, next_futures, roll_date): | |
roll_proportion = next_futures[roll_date]/previous_futures[roll_date] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
#load data from your preferred source | |
data = pd.read_csv("PATH/TO/FILE/futures_rolling.csv", index_col = [0], parse_dates=True) | |
june_21 = data["VX-2021M"] | |
july_21 = data["VX-2021N"] | |
def panama_adjustment(previous_futures, next_futures, roll_date): | |
roll_gap = next_futures[roll_date] - previous_futures[roll_date] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load R packages | |
library(shiny) | |
library(leaflet) | |
library(RColorBrewer) | |
library(xts) | |
library(rgdal) | |
#helper function for choropleth animation | |
setShapeStyle <- function( map, data = getMapData(map), layerId, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sliderInput("dateSel", "Date", | |
min = min(covidData$Date_reported), | |
max = max(covidData$Date_reported), | |
value = min(covidData$Date_reported), | |
step = 1, | |
timeFormat = "%d %b %y", | |
animate = animationOptions(interval = 500, loop = FALSE) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create choropleth map | |
leaflet(world_spdf) %>% | |
addTiles() %>% | |
setView(lat = 0, lng = 0, zoom=2) %>% | |
addPolygons( | |
layerId = ~ISO2, | |
fillColor = ~colorPalette(Cases), | |
stroke = TRUE, | |
fillOpacity = 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create map with circle markers | |
leaflet(world_spdf) %>% | |
addTiles() %>% | |
setView(lat = 0, lng = 0, zoom=2) %>% | |
addCircleMarkers(lng = ~LON, | |
lat = ~LAT, | |
radius = ~log(Cases) * 2, | |
weight = 1, | |
opacity = 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(leaflet) | |
library(rgdal) | |
library(RColorBrewer) | |
#load spatial data | |
world_spdf <- readOGR( | |
dsn = getwd() , | |
layer = "TM_WORLD_BORDERS_SIMPL-0.3", | |
verbose = FALSE | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
covidData <- read.csv("https://covid19.who.int/WHO-COVID-19-global-data.csv", fileEncoding="UTF-8-BOM", stringsAsFactors = FALSE) | |
covidData <- na.omit(covidData) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
#you only have to do this once! | |
download.file("http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip" , destfile="world_shape_file.zip") | |
system("unzip world_shape_file.zip") | |
#loading the world borders spatial polygons data frame | |
world_spdf <- readOGR( | |
dsn= getwd() , | |
layer="TM_WORLD_BORDERS_SIMPL-0.3", |
NewerOlder