Skip to content

Instantly share code, notes, and snippets.

@flare9x
flare9x / sind_cosd.jl
Created May 18, 2023 05:19
sine and cosine
# julia language
using Plots
# n = degrees
n = 360
sin_out = fill(NaN,n)
cos_out = fill(NaN,n)
for i = 1:size(sin_out,1)
# julia function - sind,cosd = sin/cos in degrees
sin_out[i] = sind(i)
cos_out[i] = cosd(i)
@flare9x
flare9x / rsi.jl
Last active July 13, 2022 02:40
rsi indicator
"""
```
Relative strength index
rsi(x::Array{T}; n::Int64=14)::Array{Float64}
Indicator weights the average gain and loss correctly not averaging over 0 values. Accounts for NaN in the calculation
using NaNMath; nm=NaNMath
```
"""
function rsi(x::AbstractArray{T}; n::Int64=14)::Array{Float64} where {T<:Real}
dims = size(x,1)
@flare9x
flare9x / dictionary.c
Last active May 7, 2022 22:28
CS50 Speller Solution
// Implements a dictionary's functionality
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <math.h>
@flare9x
flare9x / collatz_recursion.jl
Last active April 24, 2022 05:01
Collatz conjecture
function collatz(n::Int64)::Int64
while(n != 1)
# base case
if n == 1
break
end
# if even
if (n % 2 == 0)
n = Int64(n /2)
elseif (n % 2 != 0)
@flare9x
flare9x / file_size_df_to_csv.py
Created April 5, 2022 21:40
list file and file size in a directory and export to .csv
# import python modules
import os
import pandas as pd
# directory name from which
# we are going to extract our files with its size
path = "C:/Users/andre/Downloads/OneDrive_1_4-5-2022"
# Get list of all files only in the given directory
fun = lambda x: os.path.isfile(os.path.join(path, x))
@flare9x
flare9x / spot_crude_frequency_distribution.jl
Created March 4, 2022 15:35
spot_crude_frequency_distribution.jl
using FredApi, DataFrames, Dates, Statistics, Plots, TimeSeries
# load FRED oil data
key = "your_key"
set_api_key(key)
# full sample
crude_oil = get_symbols("WTISPLC")
price = values(crude_oil)
@flare9x
flare9x / cdc_covid.jl
Created October 4, 2021 14:12
CDC Covid19 data
using DataFrames, Plots, CSV, Dates, Statistics
# Load CDC NHCS covid weekly data
nhcs = CSV.read("C:/Users/andrew.bannerman/Desktop/Julia/scripts/Provisional_COVID-19_Deaths_by_Week__Sex__and_Age.csv", DataFrame, header=true, delim=",")
#rename columns
colnames = ["Data_as_of", "State", "MMWR_Week", "End_Week", "Sex", "Age_Group", "Total_Deaths", "COVID19_Deaths"]
rename!(nhcs, colnames)
# Subset data only for all sexes
@flare9x
flare9x / GHCN.jl
Created August 10, 2021 12:42
GHCN parse .dly files, export as CSV, build dataframe for running statistics
# GHCN data
using CSV
using DataFrames
using Dates
using Statistics
using Plots
# Data
# USCHN
# https://cdiac.ess-dive.lbl.gov/epubs/ndp/ushcn/ushcn.html#:~:text=The%20United%20States%20Historical%20Climatology%20Network%20%28USHCN%29%20is,observing%20stations%20across%20the%2048%20contiguous%20United%20States.
@flare9x
flare9x / GHCN_dly_file_parser.jl
Last active August 9, 2021 12:23
NOAA GHCN data is fixed width data - this parses the .dly files and exports as .csv
# Data: https://www.ncei.noaa.gov/access/metadata/landing-page/bin/iso?id=gov.noaa.ncdc%3AC00861
######################################################################################################
# load .dly data file
# load as 1x string per row
# split the string per the readme .txt element / column position (static)
# export as .csv
######################################################################################################
# read all files in directory
all_dly_files = cd(readdir, "C:/Users/andrew.bannerman/Desktop/Julia/scripts/GHCN data/ghcnd_all/")
@flare9x
flare9x / ohlc_plots.jl
Last active July 5, 2021 22:42
Using Plots Julia Package - Plot Finance OHLC data
using CSV, DataFrames, Plots
# load data
data = CSV.read("D:/Model Book/pattern recognition/data_store/MOXC.csv",header=true)
# Prepare data for OHLC plot
n = size(data,1)
high_p = Float64.(data.high)
low_p = Float64.(data.low)
open_p = Float64.(data.open)