Docsity

StockX Programming Language Reference Manual, Summaries of Logic

Toggle sidebar
bg1
StockX
Jesse Van Marter jjv2121
Ravie Lakshmanan rl2857
Ricardo Martinez rmm2222
Sophie Lucy sjl2185
Language Reference Manual
Contents
Introduction 2
Lexical Conventions 3
Tokens 3
Identifiers 3
Comments 3
Whitespace 3
Separators 3
Reserved Words and Symbols 3
Data Types 5
Branch Control 7
Expressions 8
Declaration and Assignment 8
Arithmetic Operators 8
Relational Operators 8
Logic Operators 8
Functions 10
Built-in Functions 10
Function Definition 10
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download StockX Programming Language Reference Manual and more Summaries Logic in PDF only on Docsity!

StockX

Language Reference Manual

 - Jesse Van Marter jjv - Ravie Lakshmanan rl - Ricardo Martinez rmm - Sophie Lucy sjl 
  • Introduction Contents
  • Lexical Conventions
    • Tokens
    • Identifiers
    • Comments
    • Whitespace
    • Separators
    • Reserved Words and Symbols
  • Data Types
  • Branch Control
  • Expressions
    • Declaration and Assignment
    • Arithmetic Operators
    • Relational Operators
    • Logic Operators
  • Functions
    • Built-in Functions
    • Function Definition

Introduction

The financial industry has been a perfect space for the use of programming languages because of the heavy reliance on mathematical calculation and accuracy involved in gaining successful returns. Technology has allowed people to be more precise in their trades and experimental in their strategies. Thanks to the amount of historical as well as real time stock market data publically available, there are infinite possibilities to the application of a financial programming language. By using such resources, we intend to build a language that make it easy for the user to implement complex algorithms to perform sophisticated financial analysis.

order portfolio struct array true false

Boolean Logic Operators

and or not

Branch Control and Loops

if else for while return

Functions

function void return

Built-in Functions

delta stddev correlation covariance regression ewma lma

Data Types

int

  • a string of numeric characters without a decimal point, and an optional sign character

float

  • a string of numeric characters that can be before and/or after a decimal point, with an optional sign character

bool

  • a binary variable where value can be either true or false

null

  • the value of an uninitialized object

string

  • a finite sequence of ASCII characters, enclosed in double quotes e.g. “we are stockx”

struct A struct is a structure that allows the user to create their own custom data-type. A struct may hold variables and/or functions. The syntax for creating a struct is as follows:

struct studentStruct = { name : string, age : int, func : myfunc //where myfunc is a built-in or user-defined //function }

To access struct fields, use a dot in between the struct and its fields.

e.g. int myAge = studentStruct.age; studentStruct.func();

array

  • arrays only hold elements of the same type

● .price: the price of the stock at the time the order is placed ● .time: the timestamp at which the order is executed

portfolio

A type that holds the order history and thus the list of stocks owned.

Branch Control

if

  • conditional if statement are followed by a boolean expression

e.g. if(x==2){return true}

else

  • An else statement may follow an if statement
  • A statement list then follows

e.g. if(x==2) {retu rn true} else{return false}

for

The for statement allows for looping over a range of values. The format is as follows:

e.g. for (initiali zation; termination; update) { stmt }

The initialization begins the for statement and is executed only once (before the loop begins).

The termination is a boolean expression that is checked for before each loop. When it returns false, the loop terminates.

The update is an expression that occurs once after each loop, and should modify the variable(s) being checked for in the termination.

while

The while statement is used for looping so long as a boolean expression inside of the while statement evaluates to true. The syntax is as follows:

e.g. while (expression) { stmt }

return

The return keyword is used both in function declarations, and inside of functions to return a value. The syntax is as follows:

return expr;

Expressions

Declaration and Assignment

The general syntax is as follows:

● ;

● examples: int x; float number; string name;

● Arrays can be declared as follows - array ;

e.g. array string whoweare = [“we”, “are”, “stockx”];

Arithmetic Operators

  • addition
  • subtraction
  • multiplication / division % modulus += increment -= decrement *= multiply and assignment /= division and assignment %= modulus and assignment ^ power

Relational Operators

= equal to == logical equal to != not equal to < less than <= less than or equal to

greater than = greater than or equal to

Logic Operators

and

  • logical intersection of two expressions

e.g. 0 and 1 evaluates to 0(false)

or

  • logical union of two expressions

e.g. 1 or 0 evaluates to 1(true)

not

  • logical negation of an expression

e.g. not 1 evaluates to 0

  • Given an explanatory variable array x and dependent variable array y and a number n, regression() function computes the expected dependent y-value at x=n using linear regression
  • regression(x,y, 11) where x and y are arrays will compute the linearly regressed “expected” value of y at x=11.

ewma

  • Calculates exponentially weighted moving average of time series array. Takes in array of a time series and a center of mass. Center_of_mass= (length_of_ema-1)/2.
  • ewma(goog.prices, 9.5) for a 20day ewma

lma

  • Calculates linear moving average of time series array. Takes in time series array, length of average, and boolean for weighted moving average. If True, will return weighted moving average. If false will return simple moving average.
  • lma(goog.prices, 10, true) will return a 10 day weighted moving average of google prices.

Function Definition

Functions are defined in the following format:

function () return (){ }

e.g. function max( float a, float b) return (flo at) { //Statement list if(a > b ) {return a;} else{return b;}; }