Skip to content

Instantly share code, notes, and snippets.

@smartinsightsfromdata
smartinsightsfromdata / options.adoc
Created September 29, 2015 22:26 — forked from johnymontana/options.adoc
My entry for the Neo4j GraphGist December competition. Very simplified options trading in a graph.

Options Trading As A Graph


Introduction

This GraphGist will begin to explore how stock option data can be modeled as a graph, some simple Cypher queries for calculating payout at expiration for an options contract and a very basic look at finding profitable options trades given a specific forecast. Please note that some of the concepts here have been simplified and are only meant as an educational overview of exploring Neo4j and graph data modeling.

library(R6)
library(shiny)
###
### Create a simple R6 class with a public dummy value
###
DummyClass <- R6Class("DummyClass",lock_objects=FALSE,
@smartinsightsfromdata
smartinsightsfromdata / Dockerfile
Last active May 14, 2020 17:58
Dockerfile for Shiny Server Pro with Shiny examples
FROM ubuntu:14.04
MAINTAINER Winston Chang "winston@rstudio.com"
# =====================================================================
# R
# =====================================================================
# Need this to add R repo
RUN apt-get update && apt-get install -y software-properties-common
FROM ubuntu:14.04
MAINTAINER Winston Chang "winston@rstudio.com"
# =====================================================================
# R
# =====================================================================
# Need this to add R repo
RUN apt-get update && apt-get install -y software-properties-common

Analysis over Finance and Portfolio Management

Most Finance portfolio management’s would be using RDBMS. But the same could be built with neo4j in a much succint manner. The analysis that can be done over it is interesting too. Consider the system has the data for x members, we can get analysis as follows:

  • How much percentage people spend money on a particular liability, say loans.

  • How much percentage does a particular asset contribute to average earnings.

library(rgeos)
data(wrld_simpl)
plot(wrld_simpl, col='white', bg='grey9', border=NA)
limx <- c(-6,1)
limy <- c(49,60)
plot(wrld_simpl, xlim=limx, ylim=limy, col='white', bg='grey9', border=NA)
# Apply RDP algorithm with distance variable = 0.4 degrees
@smartinsightsfromdata
smartinsightsfromdata / app.R
Last active August 29, 2015 14:19 — forked from jcheng5/app.R
library(DT)
library(shiny)
# options(shiny.reactlog=TRUE)
id <- 1:10
label <- paste0("lab","-",id)
ratio <- runif(10, 1.0, 10.0)
ratio <- round(ratio,0)
df <- ds <- data.frame(id=id, label=label,ratio=ratio, stringsAsFactors = FALSE)
library(shiny)
shinyServer(function(input, output, session) {
# The number of iterations to perform
maxIter <- 50
# Track the start and elapsed time
startTime <- Sys.time()
output$elapsed <- renderText({

Favicon from Plot in R Shiny

Once I saw R.devices function toFavicon I just had to figure out how to use it to dynamically change the favicon with a plot from R. Here is one way to accomplish it, but note the dangerous eval(parse(...)) in line 14, so be careful if you are using for nonpersonal use.

Non-Shiny Use

For non-shiny use, we can see it work with htmltools.

library(htmltools)
library(R.devices)
---
title: "Changes in homicide rates"
output: html_document
---
I've updated the [mxmortalitydb](https://github.com/diegovalle/mxmortalitydb) package to include 2013 data. This data only packages includes all injury intent deaths (accidents, homicides, suicides and unspcified intent) that were registered in Mexico from 2004 to 2013. You can use the package to calculate changes and trends in homicide rates in the most violent metro areas or big municipios.
```{r}
#if (!require('devtools')) install.packages('devtools')