Calculator

Perform calculations in an interactive programming environment.

1. Overview

The Calculator is a scratchpad for writing and executing HHLang code with immediate results — like a REPL or interactive notebook. Variables you define persist across lines within the same session, making it easy to build up complex calculations step by step.

2. Getting Started

  1. Open Calculator from the Start Menu.
  2. Type an expression in the code editor (e.g., AAPL.close().last()) and press Enter.
  3. The result appears immediately.
  4. Define variables to reuse in subsequent expressions.

3. The Code Editor

The code editor is the main input area for writing HHLang code. Press Ctrl+E to focus the editor from anywhere in the window.

4. Results Panel

The results panel shows calculation results in a scrolling list. Each executed expression displays its result inline, updating in real-time as you type.

5. Context Variables Panel

This panel displays all variables currently in scope with their live values. It is useful for debugging — you can inspect intermediate values without adding print statements.

6. Log Panel

The log panel shows execution logs, warnings, and errors. Error messages are highlighted for easy identification. Check this panel when an expression produces unexpected results.

7. Evaluation Context

The "value on date" setting controls what date time-sensitive metrics use when computing values. Adjust this in the ribbon to evaluate expressions as of a specific date.

8. Keyboard Shortcuts

ShortcutAction
Ctrl+EFocus the code editor.
Ctrl+GClear all code and results.
EnterExecute the current expression.

9. Example Session

// Look up an instrument's closing price
TimeSeries price = AAPL.close()

// Get the most recent value
Double lastPrice = price.last()

// Compute a 20-day simple moving average
TimeSeries sma = price.sma(20)

// Check if price is above the moving average
Boolean aboveSma = lastPrice > sma.last()

// Calculate daily returns
TimeSeries returns = (price - price.lag(1)) / price.lag(1)

10. Tips

11. See Also