Skip to content

Instantly share code, notes, and snippets.

View Beliavsky's full-sized avatar

Beliavsky

View GitHub Profile
@Beliavsky
Beliavsky / xlower_case_fortran.py
Created August 22, 2021 00:23
Convert free source form Fortran to lower case, except for comments
"""convert Fortran code to lower case except for comments
usage: python xlower_case_fortran.py <source_file>
The script writes lower case code to standard output.
"""
from sys import argv
source_file = argv[1]
fp = open(source_file,"r")
for line in fp:
text = line.rstrip()
ipos = text.find("!")
@Beliavsky
Beliavsky / pdi_adjnav_cef_analyzer.csv
Last active April 12, 2020 22:58
PDI net asset values adjusted for dividends from CEF Analyzer
AdjNAV
2012-05-25 8.87
2012-05-29 8.87
2012-05-30 8.87
2012-05-31 8.9
2012-06-01 8.89
2012-06-04 8.87
2012-06-05 8.93
2012-06-06 8.96
2012-06-07 9.01
! RESULTS:
! #paths initial ann_drift ann_vol min max <terminal> terminal terminal-max sd(terminal) %bottom
! 100000 100.00 0.15 0.40 77.99 145.60 116.18 115.95 -29.65 48.21 4.52
! 100000 100.00 0.15 0.40 77.97 145.67 116.18 116.04 -29.63 48.30 4.39
! 100000 100.00 0.15 0.40 77.92 145.58 116.18 115.88 -29.70 48.25 4.33
! 100000 100.00 0.15 0.40 78.02 145.96 116.18 116.27 -29.69 48.64 4.41
! 100000 100.00 0.15 0.40 78.02 145.53 116.18 115.93 -29.60 47.89 4.37
module statistics_mod
implicit none
public :: dp,mean,sd,random_normal
@Beliavsky
Beliavsky / xib.r
Last active January 17, 2020 04:21
Get historical quotes from Interactive Brokers
# 01/16/2020 11:14 PM gets historical quotes for specified symbols at various frequencies
.proctime00 = proc.time()
library(IBrokers)
tws <- twsConnect()
print.contract.details = TRUE
get.mkt.data <- FALSE
get.hist.data <- FALSE
get.intraday.data <- TRUE
tws <- twsConnect()
symbols <- c("SPY","TLT")
@Beliavsky
Beliavsky / xmacd.r
Last active November 9, 2018 03:15
R script to test a MACD trading system
# adapted from https://www.quantinsti.com/blog/an-example-of-a-trading-strategy-coded-in-r
# issue the commands install.packages("quantmod") and install.packages("PerformanceAnalytics")
# before running this script
library("quantmod")
library("PerformanceAnalytics")
plot.macd = TRUE
ndrawdowns = 3
short.pos = 0 # size of short position. Set to 0 to disallow shorting
sym = "PCI" # symbol to be tested -- can be changed
all.data = getSymbols(sym,auto.assign=FALSE)
@Beliavsky
Beliavsky / xunused_gfortran.py
Last active June 24, 2018 02:22
Python 2/3 script to list unused variables from gfortran compiler messages
# 2018-06-23
# list unused variable from gfortran output
# valid Python 2 and Python 3
from sys import argv
compiler_message_file = argv[1] # produced by command such as gfortran 2> err_msg.txt -c -Werror=unused_variable source.f90
fp = open(compiler_message_file,"r")
err_str = "Error: Unused variable"
print("unused variables:")
for line in fp:
text = line.strip()
program test
! 05/23/2018 11:49 AM times varies loop methods with global or block variables -- motivated by comp.lang.fortran thread "ASSOCIATE inside loops" https://groups.google.com/forum/#!topic/comp.lang.fortran/TBYnHxFIrS0
use, intrinsic :: iso_fortran_env
integer(int64), parameter :: n = 2**25
integer(int64) :: i, t0, t1, count_rate
integer, parameter :: nways = 6
real, dimension(n) :: x, y, ysum(nways), dt(nways)
character(*), parameter :: fmt1 = "(a14,1x,f8.4)"
logical, parameter :: print_sums = .false., print_each = .false.
character (len=10) :: methods(nways) = ["global ", &
@Beliavsky
Beliavsky / gist:8480793d8be5386788dd3485eff891ca
Created May 24, 2018 20:50
timings of Fortran code xblock_sub.f90
global associate block no_temp forall do_concurrent
gfortran 0.4640 0.3598 0.3601 0.3446 0.2281 0.2222
gfortran -O3 0.1914 0.1079 0.1097 0.1072 0.1093 0.1080
ifort 0.1475 0.0728 0.0737 0.0749 0.0718 0.0718
ifort -O3 0.1488 0.0714 0.0718 0.0722 0.0718 0.0724
@Beliavsky
Beliavsky / cef_quotes_iex.html
Last active May 1, 2018 19:19
Closed-End Fund quotes
<!-- 05/01/2018 10:31 AM display quotes for all CEFs -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>Closed-End Funds</title>
<link rel="icon" href="https://d3v3cbxkdlyonc.cloudfront.net/stocks/favicon.ico">
<meta name="description" content="A free, lightweight, blazing-fast page to get stock quotes using the IEX API">