Here we pull in the data we need from Velocity (via API) and Coingecko (for filling in missing redemption prices)
#step1: pull in redemption data from velocity API:
socks.redemptions <- readLines(
con = "https://api.flipsidecrypto.com/api/v2/queries/49a23b5e-dc8f-4f48-b08f-771583e81028/data/latest"
) %>% fromJSON() %>% rbindlist(fill = TRUE)
socks.redemptions$date <- as.Date(socks.redemptions$block_timestamp)
#step 2: pull in prices from coingecko to fill in where we are missing prices
coingecko.prices <- read.csv(file.path(kDataPath,"socks-usd-max.csv")) %>% data.table()
coingecko.prices$date <- as.Date(coingecko.prices$snapped_at)
# now we're just joining and filling in and calculating a moving weighted average!
socks.redemptions <- merge(
socks.redemptions[,list(date,block_timestamp,usd_price,socks_redeemed,cumulative_redemptions)],
coingecko.prices[,list(date,cg_price = price)],
by = "date",
all.x = TRUE
)
socks.redemptions[ is.na(usd_price) & !is.na(cg_price), usd_price := cg_price ]
#have a look at the data table..
tail(socks.redemptions)
## date block_timestamp usd_price socks_redeemed
## 1: 2020-10-08 2020-10-08T02:29:40Z 2821.654 0.000050000
## 2: 2020-10-08 2020-10-08T02:01:52Z 2825.901 0.000050000
## 3: 2020-10-23 2020-10-23T04:38:35Z 3879.624 0.001800307
## 4: 2020-11-10 2020-11-10T23:30:27Z 2501.029 1.000000000
## 5: 2020-11-12 2020-11-12T11:40:38Z 2855.033 1.000000000
## 6: 2020-11-13 2020-11-13T23:16:17Z 3326.282 1.000000000
## cumulative_redemptions cg_price
## 1: 182.0002 2848.414
## 2: 182.0001 2848.414
## 3: 182.0020 3633.353
## 4: 183.0020 2427.243
## 5: 184.0020 2872.442
## 6: 185.0020 2903.555
Looking good at ~185 redemptions (matches what unisocks.exchange reports for redemptions so far).
We notice we’re missing prices prior to 2020-02-25 in both of our sources, so we take a look at the plot of prices to see if we can reasonably fill it in with a best estimate… (see below)
The plot shows a pretty stable price for the first several months of SOCKS activity, so let’s use the average price over the first 30 days of activity as our “dumb” fill-in for the earliest redemptions.
plot(as.xts(head(coingecko.prices[,list(date,price)],90)), main = "First 90 Days of Coingecko SOCKS prices")
early.price.fill <- mean(head(coingecko.prices$price,30))
print(early.price.fill)
## [1] 73.59566
socks.redemptions[ is.na(usd_price), usd_price := early.price.fill ]
socks.redemptions[,red_weight := socks_redeemed / sum(socks_redeemed) ]
socks.redemptions[,average_redemption_value := cumsum(red_weight * usd_price) / cumsum( red_weight ) ]
plot(as.xts(socks.redemptions[,list(date,usd_price,average_redemption_value)]),
main = "Weighted Cumulative Average of SOCKS Redemption USD Value")
tail(socks.redemptions)
## date block_timestamp usd_price socks_redeemed
## 1: 2020-10-08 2020-10-08T02:29:40Z 2821.654 0.000050000
## 2: 2020-10-08 2020-10-08T02:01:52Z 2825.901 0.000050000
## 3: 2020-10-23 2020-10-23T04:38:35Z 3879.624 0.001800307
## 4: 2020-11-10 2020-11-10T23:30:27Z 2501.029 1.000000000
## 5: 2020-11-12 2020-11-12T11:40:38Z 2855.033 1.000000000
## 6: 2020-11-13 2020-11-13T23:16:17Z 3326.282 1.000000000
## cumulative_redemptions cg_price red_weight average_redemption_value
## 1: 182.0002 2848.414 2.702673e-07 319.0743
## 2: 182.0001 2848.414 2.702673e-07 319.0750
## 3: 182.0020 3633.353 9.731282e-06 319.1102
## 4: 183.0020 2427.243 5.405347e-03 331.0331
## 5: 184.0020 2872.442 5.405347e-03 344.7504
## 6: 185.0020 2903.555 5.405347e-03 360.8666
So we can see here that the weighted cumulative redemption price (if we trust our price data of course) is ~$360 per .. sock.
Also: Velocity + R == :heart-emoji: