Skip to content

Instantly share code, notes, and snippets.

View zimana's full-sized avatar

Pierre DeBois zimana

View GitHub Profile
library(cryptoQuotes)
#
x <- data(ATOMUSDT) #sample data, USDT denominated ATOMS
# Start here to learn what is available. 5 available functions and 6 add functions in the library
# add functions highlight visuals
# Etherium ETH, Litecoin LTC, Bitcoin Cash BCH
# See if you can use Litecoin or Ripple(XRP). ETH is ok below for Medium article.
availableTickers(source = "bitmart", futures = TRUE)
availableIntervals(source = "binance", futures = TRUE)
@zimana
zimana / gt_10updates.R
Created January 30, 2024 17:14
gt 0.10
library(gt)
library(readxl)
table <- read_xlsx("Table_trial.xlsx")
table_gt <- gt(table)
table_gt <-
table_gt |>
tab_header(
title = "Sales during campaign",
@zimana
zimana / Quantmod_Example.R
Created November 16, 2023 15:16
Quantmod
# November 13th, 2023
library(quantmod)
startdate <- "2015-01-05"
gmprices <- getSymbols('GM', from=startdate, auto.assign = F)
head(gmprices,10)
gmreturn <- ROC(gmprices, type="discrete")
print(gmreturn)
# explore Delt function -- can I use GM column of open and close
chart_Series(gmreturn)
#
@zimana
zimana / Probability_Dist_Example.R
Created November 13, 2023 20:15
Probability Distribution
# November 4th, 2023
#
# dbinom(k,n,p)
# k - value at which probability must be determined
# n - number of trials
# p - probability of success on each trial
#
# Discrete probability distribution -- Probability of a die side(x) being equal to 3 based on 20 tries
die_side3 <- dbinom(x=3, size= 20, prob=1/6)
# [1] 0.2378866
@zimana
zimana / MarkovChain_Basic.R
Created November 4, 2023 02:20
Markov Chain Example
library(markovchain)
# library includes data called rain
# Up to date as of November 3rd
# define transition matrix using random normal probabilities
Weather<- c("Sunny", "Rain")
Weatherchange <- matrix(c(0.9,0.1,0.5,0.5), nrow=2, byrow= TRUE, dimnames = list(Weather, Weather))
Weatherchange
# Matrix is a Discrete Time Markov Chain
WeatherZone <- new("markovchain",
@zimana
zimana / pair_plot_example.r
Created October 23, 2023 19:54
Pair Plot R programming
library(ggplot2)
library(GGally)
# pairs(df) dataframe used in the plot
cars <- gt::gtcars
carsspecs <- data.frame(cars$hp,cars$trq, cars$mpg_c, cars$mpg_h)
carsspecs <- carsspecs[-40,]
pairs(carsspecs)
# diagonal boxes are for variables
# no statistical summaries; ggpairs from GGally provides that via correlations and a distribution of data
@zimana
zimana / Binning_Example.R
Created October 1, 2023 23:08
Binning in R programming
library(Hmisc) # for cut2
# Note: The dataset gtcars is from the gt library
carset <- gt::gtcars
cutpoints <- cut2(carset$mpg_c, g=3, onlycuts=TRUE) # shows only the cut points
bins <- cut2(carset$mpg_c, g=3)
car_bins<- data.frame(carset$mfr, carset$model, bins) # shows which vehicle is in which bin
bins_cap <- cut2(carset$mpg_c, g=3,include.lowest = T, right = T)
car_bins<- data.frame(carset$mfr, carset$model, bins_cap)
@zimana
zimana / Dendrogram_segmentation.R
Last active September 3, 2023 18:04
Dendrogram_Segmentation
# Posted: Sept 3rd, 2023
#
# searchConsoleR download data from Google Search Console
library(searchConsoleR)
# factoextra provides the dendrogram function fviz_dend
library(factoextra)
#
# for plotting side by side
library(gridExtra)
@zimana
zimana / cuts2.R
Created May 1, 2023 01:32
Cuts2 function
library(Hmisc)
carset <- gt::gtcars
mileage <- cut2(carset$mpg_c, c(0,15,20,25,30,35))
mileage_min <- cut2(carset$mpg_c, m=10)
mileage_quant <- cut2(carset$mpg_c, g=2)
table(cut2(carset$mpg_c, m=10))
table(cut2(carset$mpg_c, g=2))
@zimana
zimana / cut_example.r
Created March 20, 2023 12:01
Cut Function Examples
# Note: The dataset gtcars is from the gt library
carset <- gt::gtcars
mileage <- cut(carset$mpg_c, breaks = c(0,15,20,25,30,35))
mileage_label <- cut(carset$mpg_c,breaks = c(0,15,20,25,30,35),labels = c("extremely low", "low", "midpack", "high", "extremely high"))
# Note: The number of labels must match the number of bins
price <- cut(carset$msrp, breaks = c(0,75000,100000,200000,Inf), ordered_result=T, labels = c("premium", "luxury", "ultra luxury", "exclusive"))