Skip to content

Instantly share code, notes, and snippets.

@flare9x
flare9x / risk_management.jl
Last active July 17, 2021 22:26
Risk management iterations
# Risk management simulations
using CSV, DataFrames, StatsBase, Random
##############################
## Trades to double
##############################
winPerc = .46
AvgWin = .14
@flare9x
flare9x / psv_overhaul_export.R
Created October 5, 2020 16:13
filter PSVs to leave only items without overhauls
#####################################
# Export PSVs with EXERNAL / DEFAULT schedules (own export)
# Find PSVs with NO OVERHAUL schedule (own export)
# Compare - filter by no overhaul
#####################################
# load data
externals = read.csv("C:/Users/Andrew.Bannerman/Desktop/MARS/PSV KPI project/externals.csv")
internals = read.csv("C:/Users/Andrew.Bannerman/Desktop/MARS/PSV KPI project/overhauls.csv")
@flare9x
flare9x / required_structural_thickness.jl
Last active February 10, 2024 21:04
Calculating the Required Structural Thickness of Pipe Using Beam Stress Theory
#############################################################################################
# Calculating the Required Structural Thickness of Pipe Using Beam Stress Theory
#############################################################################################
# Input parameters
P = 850 # pressure
Do = 12.75 # outside diameter
S = 17900 # code allowable stress
E = .85 # weld joint efficieny
W = 1.0
Y = 0.4
@flare9x
flare9x / rolling_equity_cash_flow_all_investments.jl
Last active August 10, 2020 04:20
Rolling equity and cash flow all real estate investments
using Dates
using DataFrames
using Gadfly
using CSV
using Statistics
### methodology
# 1. amoritzation schedule per property
# 2. initial down payment + principal + any estimated equity due to renovations (conservative estimates)
# 3. account for any refinances - amooritization schedule for each and join
@flare9x
flare9x / amortization_example.R
Created April 25, 2020 19:25
Code for amortization schedule
# Amortization
# https://www.wikihow.com/Calculate-Amortization
# Step 1 - Gather the information you need to calculate the loan's amortization
property_value = 240000
loan_amount = .75
down_payment = property_value-(loan_amount * property_value)
debt_borrowed = property_value - down_payment
interest_rate = 0.06 # annual interest rate
loan_term = 360 # months
@flare9x
flare9x / long_lat_geommap.R
Created April 25, 2020 19:23
Harris County Tax List - Use address to find longitude and latitude - plot on map
library(ggmap)
google_map_api_key = ##
data = read.csv("C:/Users/Andrew.Bannerman/Desktop/Real Estate/County Tax Lists/harris_county_tax_list/Real_acct_owner/filtered_list.csv", stringsAsFactors = F,header=T, sep=",")
real_acct_names = c("account","tax_year","mailto","mail_addr_one","mail_addr_two","mail_city","mail_state","mail_zip","mail_country","undeliverable","str_pfx","str_num","str_num_sfx","str_name","str_sfx","str_sfx_dir","str_unit","site_addr_one","site_addr_two","site_addr_three","state_class","school_dist","map_facet","key_map",
"neighborhood_code","neighborhood_group","market_area_one","market_area_one_dscr","market_area_two","market_area_two_dscr","econ_area","econ_bld_class","center_code","yr_impr","yr_annexed","splt_dt","dsc_cd","nxt_building","total_building_area","total_land_area","acerage","cap_account","shared_cap_code","land_value","improvement_value","extra_feartures_value","ag_value","assessed_value","total_appraised_value",
"total_market_value
@flare9x
flare9x / risk_matrix_plot_pof_cof.R
Created April 25, 2020 19:21
API 581 POF and COF Risk Plot - Nominal Thickness Rank
data = read.csv("C:/Users/Andrew.Bannerman/Desktop/MARS/risk studies/for_r_plot.csv",header=T)
data = data[order(data$COF.Rank),]
#data = data[sample(nrow(data)),]
head(data)
names = c("Corrosion Loop","CL","Service","POF","Nominal Wall Thickness Category","COF Rank","Risk")
colnames(data) = names
@flare9x
flare9x / max_FCAml_MAWPr_relation_P.R
Last active March 28, 2020 23:32
run in conjunction with FCAml iteration julia language
data = read.csv("C:/Users/Andrew.Bannerman/Desktop/MARS/15. PoC/3.24/PS_out_FCA.csv", header=T, stringsAsFactors = F)
FCAml = as.numeric(as.vector(data[6,2:length(data)]))
Rt = as.numeric(as.vector(data[9,2:length(data)]))
MAWPr = round(as.numeric(as.vector(data[18,2:length(data)])),digits=0)
MAWPr_P_intersection = ifelse(MAWPr > P,1,0)
df = data.frame(FCAml,Rt,MAWPr,MAWPr_P_intersection)
@flare9x
flare9x / api_581_POF_ext_cr.jl
Last active April 22, 2020 22:04
POF analysis :: API 581 for external corrosion
using Distributions
using CSV
using DataFrames
using Statistics
using Cairo
using Gadfly
# read data
colnames = ["P&ID","Size","Service","Line_No","Sch","Spec","Exp Code","Design Temp"]
@flare9x
flare9x / r_plots_part5_LTA_sensitivity_analysis.R
Last active April 25, 2020 19:46
r_plots_part5_LTA_sensitivity_analysis
# Plots for PArt 5 LTA sensitivity analysis
library(sm)
library(pheatmap)
library(ggplot2)
# original Grid
M1 = c(0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300)
M2 = c(0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.100, 0.220, 0.280, 0.250, 0.240, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300)
M3 = c(0.300, 0.300, 0.300, 0.300, 0.300, 0.215, 0.255, 0.215, 0.145, 0.275, 0.170, 0.240, 0.250, 0.250, 0.280, 0.290, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300)
M4 = c(0.300, 0.300, 0.300, 0.300, 0.300, 0.170, 0.270, 0.190, 0.190, 0.285, 0.250, 0.225, 0.275, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300, 0.300)