Coin flip study

Discussion in 'Strategy Building' started by digitalnomad, Oct 17, 2019.

  1. ironchef

    ironchef

    Thank you for the website.

    However, I don't have Office 365, only 2011 Mac version of Office for student and home.
     
    #31     Oct 27, 2019
  2. ph1l

    ph1l

    If you are running Cygwin on Windows (free other than the cost of Windows) or Linux, here are a few examples of retrieving current prices.
    Code:
    wget -nd -O - --quiet 'https://www.barchart.com/stocks/quotes/BRK.A' |
    perl -n -e 'BEGIN { $/ = undef; } if ($_ =~ /"lastPrice":"([^"]+)/) { my $p = $1; $p =~ s/,//g; print "$p\n"; } else { print "Unavailable\n"; }'
    
    wget -nd -O - --quiet 'https://finance.yahoo.com/quote/BRK-B' |
    perl -n -e 'BEGIN { $/ = undef; } if ($_ =~ /"regularMarketPrice":\{"raw":([^,]+)/) { print "$1\n"; } else { print "Unavailable\n"; }'
    
    curl --show-error --insecure --silent --location --max-redirs 10 --max-time 30 'https://finance.yahoo.com/quote/AMZN' |
    perl -n -e 'BEGIN { $/ = undef; } if ($_ =~ /"regularMarketPrice":\{"raw":([^,]+)/) { print "$1\n"; } else { print "Unavailable\n"; }'
    
    curl --show-error --insecure --silent --location --max-redirs 10 --max-time 30 'https://finance.yahoo.com/quote/ES=F' |
    perl -n -e 'BEGIN { $/ = undef; } if ($_ =~ /"regularMarketPrice":\{"raw":([^,]+)/) { print "$1\n"; } else { print "Unavailable\n"; }'
    
    curl --show-error --insecure --silent --location --max-redirs 10 --max-time 30 'https://www.barchart.com/futures/quotes/ESZ19' |
    perl -n -e 'BEGIN { $/ = undef; } if ($_ =~ /"lastPrice":"([^"]+)/) { my $p = $1; $p =~ s/,//g; print "$p\n"; } else { print "Unavailable\n"; }'
    
     
    #32     Oct 27, 2019
    ironchef likes this.
  3. ironchef

    ironchef

    Thank you for the suggestion.

    I don't recognize the codes. What language? VBA?
     
    #33     Oct 28, 2019
  4. ph1l

    ph1l

    wget, curl, and perl are Unix/Linux/Cygwin commands.
    These have arguments passed to the commands including the perl programs that start with "BEGIN."
    The single quote delimiter and pipe (|) are used by Unix/Linux/Cygwin shells such as bash, sh, ksh, or csh.
    For example, on my Windows 10 PC, I tested these from a Cygwin bash shell window.

    If you wanted to run these from a Windows program such as Visual Basic inside Excel, you would likely need to run a Cygwin shell from the Windows program. For example,
    Code:
    C:\cygwin64\bin\bash.exe -c "/bin/perl -e 'my $cmd = q@/bin/curl --show-error --insecure --silent --location --max-redirs 10 --max-time 30 ,2beSingleQuote,https://finance.yahoo.com/quote/ES=F,2beSingleQuote, | /bin/perl -n -e ,2beSingleQuote,BEGIN { $/ = undef; } if ($_ =~ /\"regularMarketPrice\":\{\"raw\":([^,]+)/) { print qq#$1\n#; } else { print qq#Unavailable\n#; },2beSingleQuote,@; $cmd =~ s/,2beSingleQuote,/\047/g; print `$cmd`;' > 'C:\WINDOWS\TEMP\price.txt'"
    
    run from a cmd.exe window gets the current price of E-Mini S&P 500 Dec 19 (ES=F) and puts the output in C:\WINDOWS\TEMP\price.txt. Your program could then read and C:\WINDOWS\TEMP\price.txt.

    This rather ugly code might not be the best way to parse the data returned from the curl command (I'm not a Windows programming expert :)), but it does work and the software and data source are free.
     
    #34     Oct 28, 2019