Skip to content

Instantly share code, notes, and snippets.

View Doggie52's full-sized avatar
📈

Douglas Stridsberg Doggie52

📈
View GitHub Profile
@Doggie52
Doggie52 / GenerateOptimalPortfolioWeights.py
Last active August 22, 2021 12:07
Financial portfolio optimizer (Sharpe/Vol/CVaR) with Bayesian shrinkage and filtering
def GenerateOptimalPortfolioWeights(returnsDf):
###########################################
# GENERATE MATRICES
# - CALCULATING RETURNS, VOLS AND DVOLS
# Populate annual returns
assetsReturn = []
for assetName in returnsDf:
assetReturn = returnsDf[assetName].add(1).product() - 1
@Doggie52
Doggie52 / StringExtensions.cs
Created August 16, 2018 13:01
Thread-safely write to files in C#
using System.IO;
using System.Threading;
namespace Util
{
/// <summary>
/// Various extensions to the String class.
/// </summary>
public static class StringExtensions
{
@Doggie52
Doggie52 / Timeseries_UDF.bas
Last active August 27, 2019 19:47
Microsoft Excel UDF macro to calculate Internal Rate of Return, Annualised Volatility, Annualised Downside Volatility and Maximum Drawdown of timeseries
Function DIRR(first_price_cell As Range, first_date_cell As Range) As Double
' Gets various useful numbers
Dim first_row As Long, last_row As Long, price_column As Long, date_column As Long, sheet As Worksheet
first_row = first_price_cell.Row ' first row
price_column = first_price_cell.Column ' price column
date_column = first_date_cell.Column ' date column
Set sheet = first_price_cell.Worksheet ' sheet for price
last_row = sheet.Cells(sheet.Rows.Count, price_column).End(xlUp).Row ' get the last row

Keybase proof

I hereby claim:

  • I am Doggie52 on github.
  • I am doggie52 (https://keybase.io/doggie52) on keybase.
  • I have a public key whose fingerprint is F22E EBFE EB86 77C9 A8C5 C828 E5E2 B3CD E334 772B

To claim this, I am signing this object:

@Doggie52
Doggie52 / roman_to_int.php
Created May 6, 2015 09:52
PHP: Roman numeral to int converter
<?php
/**
* Takes a roman numeral input and outputs its integer value.
*/
function roman_to_int( $in ) {
$out = 0;
$i = 0;
$prev_map = 0;
@Doggie52
Doggie52 / draw_boids.m
Last active March 26, 2016 21:55
A simple example of how to plot BOIDs or other agents on a plot in MATLAB
function Plot = draw( Plot )
% Author: Douglas Stridsberg <d@stridsberg.uk>
%
% INFO
% Redraws the plot, one BOID at a time.
% Intended to be run once every frame. The Plot object requires
% - an array of handles to old BOIDs created;
% - an array of BOID objects. These, in turn, require
% - position vectors.
%